package com.protocolterminal.AFN.entity;

import java.util.List;

import com.protocolterminal.function.FrameFunction;

public class AFN04F3 implements Interface_Data {

	@Override
	public String frametolist(String frame) throws Exception {
		
		return null;
	}

	@Override
	public String listtoframe(List<String> datalist) throws Exception {
		if (datalist.size() != 5) {
			return "";
		}

		String data = "";
		FrameFunction frameFunction = new FrameFunction();

		String[] fip = datalist.get(0).split("\\.");
		data += Integer.toHexString(Integer.valueOf(fip[0]) | 0x100).substring(1);
		data += Integer.toHexString(Integer.valueOf(fip[1]) | 0x100).substring(1);
		data += Integer.toHexString(Integer.valueOf(fip[2]) | 0x100).substring(1);
		data += Integer.toHexString(Integer.valueOf(fip[3]) | 0x100).substring(1);
		data += String.valueOf(
				frameFunction.Reverse(Integer.toHexString(Integer.valueOf(datalist.get(1)) | 0x10000).substring(1)));

		String[] sip = datalist.get(2).split("\\.");
		data += Integer.toHexString(Integer.valueOf(sip[0]) | 0x100).substring(1);
		data += Integer.toHexString(Integer.valueOf(sip[1]) | 0x100).substring(1);
		data += Integer.toHexString(Integer.valueOf(sip[2]) | 0x100).substring(1);
		data += Integer.toHexString(Integer.valueOf(sip[3]) | 0x100).substring(1);
		data += String.valueOf(
				frameFunction.Reverse(Integer.toHexString(Integer.valueOf(datalist.get(3)) | 0x10000).substring(1)));

		byte[] bs = datalist.get(4).getBytes();
		String apn = "";

		for (byte b : bs) {
			apn += Integer.toHexString(b | 0x100).substring(1, 3);
		}
		while (apn.length() < 32) {
			apn += "00";
		}

		data += apn;

		return data;

	}

}
